package site.teamo.biu.flink.tool;

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author haocongshun
 * @date 2023/11/01 14:56:30
 */
@Slf4j
public class BiuFlinkToolApplication {
    public static void main(String[] args) {
        if (args.length < 2) {
            log.warn("未指定工具类名或交互文件");
            return;
        }
        String toolClassName = args[0];
        String swapFile = args[1];
        try {
            Class<?> aClass = Class.forName(toolClassName);
            BiuFlinkToolHandler handler = (BiuFlinkToolHandler) aClass.getConstructor(new Class<?>[0]).newInstance();
            String result = handler.handle(FileUtil.readUtf8String(swapFile));
            FileUtil.writeUtf8String(result, swapFile);
        } catch (Exception e) {
            log.error("执行:{} {} 时发生错误", toolClassName, swapFile, e);
            System.exit(-1);
        }
    }
}
